package cn.gcyl.module.biz.controller.admin.useragreement;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import cn.gcyl.framework.excel.core.util.ExcelUtils;
import cn.gcyl.module.biz.controller.admin.useragreement.vo.*;
import cn.gcyl.module.biz.dal.dataobject.useragreement.UserAgreementDO;
import cn.gcyl.module.biz.service.useragreement.UserAgreementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.*;
import static cn.gcyl.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 用户协议")
@RestController
@RequestMapping("/biz/user-agreement")
@Validated
public class UserAgreementController {

    @Resource
    private UserAgreementService userAgreementService;

//    @PostMapping("/create")
//    @Operation(summary = "创建用户协议")
//    @PreAuthorize("@ss.hasPermission('biz:user-agreement:create')")
//    public CommonResult<Long> createUserAgreement(@Valid @RequestBody UserAgreementSaveReqVO createReqVO) {
//        return success(userAgreementService.createUserAgreement(createReqVO));
//    }

    @PutMapping("/update")
    @Operation(summary = "更新用户协议")
//    @PreAuthorize("@ss.hasPermission('biz:user-agreement:update')")
    public CommonResult<Boolean> updateUserAgreement(@Valid @RequestBody UserAgreementSaveReqVO updateReqVO) {
        userAgreementService.updateUserAgreement(updateReqVO);
        return success(true);
    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除用户协议")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('biz:user-agreement:delete')")
//    public CommonResult<Boolean> deleteUserAgreement(@RequestParam("id") Long id) {
//        userAgreementService.deleteUserAgreement(id);
//        return success(true);
//    }
//
//    @DeleteMapping("/delete-list")
//    @Parameter(name = "ids", description = "编号", required = true)
//    @Operation(summary = "批量删除用户协议")
//                @PreAuthorize("@ss.hasPermission('biz:user-agreement:delete')")
//    public CommonResult<Boolean> deleteUserAgreementList(@RequestParam("ids") List<Long> ids) {
//        userAgreementService.deleteUserAgreementListByIds(ids);
//        return success(true);
//    }
//
    @GetMapping("/get")
    @Operation(summary = "获得用户协议")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('biz:user-agreement:query')")
    public CommonResult<UserAgreementRespVO> getUserAgreement(@RequestParam("id") Long id) {
        UserAgreementDO userAgreement = userAgreementService.getUserAgreement(id);
        return success(BeanUtils.toBean(userAgreement, UserAgreementRespVO.class));
    }
//
    @GetMapping("/page")
    @Operation(summary = "获得用户协议分页")
//    @PreAuthorize("@ss.hasPermission('biz:user-agreement:query')")
    public CommonResult<PageResult<UserAgreementRespVO>> getUserAgreementPage(@Valid UserAgreementPageReqVO pageReqVO) {
        PageResult<UserAgreementDO> pageResult = userAgreementService.getUserAgreementPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, UserAgreementRespVO.class));
    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出用户协议 Excel")
////    @PreAuthorize("@ss.hasPermission('biz:user-agreement:export')")
//    @ApiAccessLog(operateType = EXPORT)
//    public void exportUserAgreementExcel(@Valid UserAgreementPageReqVO pageReqVO,
//              HttpServletResponse response) throws IOException {
//        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
//        List<UserAgreementDO> list = userAgreementService.getUserAgreementPage(pageReqVO).getList();
//        // 导出 Excel
//        ExcelUtils.write(response, "用户协议.xls", "数据", UserAgreementRespVO.class,
//                        BeanUtils.toBean(list, UserAgreementRespVO.class));
//    }

}